<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit|ie-comp|ie-stand"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
    <style>
        #deviceTable_wrapper {
            position: relative;
        }

        #deviceTable_length {
            position: absolute;
            bottom: -35px;
        }
    </style>
</head>
<body>
<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote mylog-info-tit" style="background: #fff;">
                <ul class="handle-box" id="conditions">
                    <li class="handle-item"><span class="layui-form-label" style="line-height: 30px;">设备名称：</span>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" placeholder="请输入设备名称" class="layui-input"
                                   v-model="deviceName">
                        </div>
                        <button class="layui-btn mgl-20" @click="getDeviceList">查询</button>
						 <span class="fr">
		            	
		            	<a class="layui-btn btn-add btn-default" id="btn-adduser"><i
                                class="linyer icon-add"></i> 添加设备</a>
		            </span>
                    </li>
                    <li class="handle-item" style="padding-top: 10px;">
                        <span class="layui-form-label">设备类型：</span>

                        <div style="height: 38px; line-height: 38px;" class="btn_block">
                            <template v-for="(item, index) in deviceTypes">
                                <label v-if="deviceType == item.typeId" class="layui-btn-block">{{item.typeName}}<input type="radio"
                                                                                                       name="sex1"
                                                                                                       :value="item.typeId"
                                                                                                       style="display: none;"
                                                                                                       v-model="deviceType"
                                                                                                       @change="getDeviceList"></label>
                                <label v-else class="layui-btn-none">{{item.typeName}}<input type="radio" name="sex1"
                                                                                             :value="item.typeId"
                                                                                             style="display: none;"
                                                                                             v-model="deviceType"
                                                                                             @change="getDeviceList"></label>
                            </template>
                        </div>

                        <!--<div class="btn_block" style="height: 38px; line-height: 38px; ">
                        	<label class="layui-btn-block">不限<input type="radio" name="sex1" value="-1" style="display: none;" v-model="deviceType" @change="getDeviceList"></label>
                        	<label class="layui-btn-none">GPRS<input type="radio" name="sex1" value="0" style="display: none;" v-model="deviceType" @change="getDeviceList"></label>
                        	<label class="layui-btn-none">WIFI<input type="radio" name="sex1" value="1" style="display: none;" v-model="deviceType" @change="getDeviceList"></label>
                        </div>-->
                    </li>
                    <li class="handle-item">
                        <span class="layui-form-label">应用场景：</span>
                        <div style="height: 38px; line-height: 38px;" class="btn_block">
                            <template v-for="(item, index) in monitorScene">
                                <label v-if="sceneId == item.sceneId" class="layui-btn-block">{{item.sceneName}}<input type="radio"
                                                                                                        name="scene_id"
                                                                                                        :value="item.sceneId"
                                                                                                        style="display: none;"
                                                                                                        v-model="sceneId"
                                                                                                        @change="getDeviceList"></label>
                                <label v-else class="layui-btn-none">{{item.sceneName}}<input type="radio"
                                                                                              name="scene_id"
                                                                                              :value="item.sceneId"
                                                                                              style="display: none;"
                                                                                              v-model="sceneId"
                                                                                              @change="getDeviceList"></label>
                            </template>
                        </div>

                    </li>
                    <li class="handle-item">
                        <span class="layui-form-label">设备状态：</span>
                        <div style="height: 38px; line-height: 38px;" class="btn_block">
                            <label class="layui-btn-block">不限<input type="radio" name="sex3" value="-1"
                                                                    style="display: none;" v-model="deviceState"
                                                                    @change="getDeviceList"></label>
                            <label class="layui-btn-none">正常<input type="radio" name="sex3" value="2"
                                                                   style="display: none;" v-model="deviceState"
                                                                   @change="getDeviceList"></label>
                            <label class="layui-btn-none">超限<input type="radio" name="sex3" value="1"
                                                                   style="display: none;" v-model="deviceState"
                                                                   @change="getDeviceList"></label>
                            <label class="layui-btn-none">异常<input type="radio" name="sex3" value="0"
                                                                   style="display: none;" v-model="deviceState"
                                                                   @change="getDeviceList"></label>
                            <label class="layui-btn-none">离线<input type="radio" name="sex3" value="3"
                                                                   style="display: none;" v-model="deviceState"
                                                                   @change="getDeviceList"></label>
                        </div>
                    </li>
                </ul>
            </blockquote>
            <div class="layui-clear">
                <div class="tableTools fr"></div>
            </div>
            <div class="layui-tab-item layui-field-box layui-show" style="position: relative;">
                <table class="table-box table-sort" id="deviceTable" lay-even="" lay-skin="nob">

                </table>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/device_list.js"></script>
<script type="text/javascript" src="js/vue/vue.js"></script>
<script src="//cdn.bootcss.com/jquery/3.2.0/jquery.js"></script>
<script src="//cdn.bootcss.com/vue-resource/1.2.1/vue-resource.js"></script>
<script>

    var vue = new Vue({
                el: '#conditions',
                data: {
                    deviceName: "",
                    deviceType: -1,
                    sceneId: -1,
                    deviceState: -1,
                    monitorScene: [],
                    deviceTypes:[]
                },
                mounted: function () {
                    this.$nextTick(function () {
                        var token = new Object();
                        token.accessToken = accessToken;
                        this.$http.get(url + "/ic-iot/users/" + adminId + "/devices/scenes",
                                {headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var noScene = new Object();
                                noScene.sceneName = "不限";
                                noScene.sceneId = "-1";
                                this.monitorScene.push(noScene);
                                this.monitorScene = this.monitorScene.concat(res.result);
                            }
                        }).catch(function (response) {
                            console.log(response)
                        });
                        this.$http.get(url + "/ic-iot/users/" + adminId + "/devices/deviceTypes",
                                {headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var noDeviceType = new Object();
                                noDeviceType.typeName = "不限";
                                noDeviceType.typeId = "-1";
                                this.deviceTypes.push(noDeviceType);
                                this.deviceTypes = this.deviceTypes.concat(res.result);
                            }
                        }).catch(function (response) {
                            console.log(response)
                        });
                    });
                },
                methods: {
                    getDeviceList: function () {
                        var params = new Object();
                        params.pageSize = 999;
                        params.currentPage = 1;
                        if (this.deviceName != "")
                            params.deviceName = this.deviceName;
                        if (this.deviceType != -1)
                            params.deviceType = this.deviceType;
                        if (this.deviceState != -1)
                            params.deviceState = this.deviceState;
                        if (this.sceneId != -1)
                            params.sceneId = this.sceneId;
                        var token = new Object();
                        token.accessToken = accessToken;
                        this.$http.get(url + "/ic-iot/admin/" + adminId + "/devices",
                                {params: params, headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var result = res.result;
                                $('#deviceTable').dataTable().fnClearTable();
                                if (result.length != 0)
                                    $('#deviceTable').dataTable().fnAddData(result);
                            }
                        }).catch(function (response) {
                            console.log(response)
                        });
                    }
                }
            }
    );

</script>
</body>
</html>